package Pp;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import Sudoku_Feldmann.numberBotton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;

@SuppressWarnings("serial")
public class GUI extends JFrame {
	
	String witch = null;
	boolean player1 = true;
	private JPanel contentPane;
	private JPanel panel;
	private JLabel lblTictactou;
	private numberBotton numBotton[] = new numberBotton[10];
	private JButton btnX;
	private JButton btnNewButton_2;
	
	
	public GUI() {
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(null);
		setContentPane(contentPane);
		
		panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		lblTictactou = new JLabel("TIC-TAC-TOU");
		lblTictactou.setHorizontalAlignment(SwingConstants.CENTER);
		lblTictactou.setBounds(118, 11, 162, 14);
		panel.add(lblTictactou);
		
		btnX = new JButton("?");
		btnX.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_btnX_actionPerformed(e);
			}
		});
		btnX.setFont(new Font("Terminator Two", Font.PLAIN, 40));
		btnX.setBounds(259, 47, 138, 71);
		panel.add(btnX);
		
		btnNewButton_2 = new JButton("=");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_btnNewButton_2_actionPerformed(e);
			}
		});
		btnNewButton_2.setFont(new Font("Terminator Two", Font.PLAIN, 40));
		btnNewButton_2.setBounds(259, 114, 138, 86);
		panel.add(btnNewButton_2);
		int m = 0;
		for(int i=0 ; i<=2; i++){
			for (int j=0 ; j<=2; j++){
				m++;
				String text = "";
				numBotton[m] = new numberBotton(m, text);
				numBotton[m].setBounds(10+j*91, 25+i*66, 91, 66);
				panel.add(numBotton[m]);
				contentPane.add(numBotton[m]);
				numBotton[m].addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent arg0) {
					int number = ((numberBotton)arg0.getSource()).getnum();
					if (numBotton[number].getText().equals("X") || numBotton[number].getText().equals("O")){
						
					}
					else{
						if (player1 == true){
							numBotton[number].setText("X");
							player1 = false;
						}
						else if (player1 == false){
							numBotton[number].setText("O");
							player1 = true;
						}
					}
				}
			});
		}
	}
}
	
	
	
	protected void do_btnX_actionPerformed(ActionEvent e) {
		witch = "?";
	}
	protected void do_btnNewButton_2_actionPerformed(ActionEvent e) {
		witch = "=";
	}
}
